package com.gitee.zjbqdzq.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;


@Data
@Entity
public class Track {
    @Id
    private Long id;
    @Column(length = 128)
    private String title;
    @Column(length = 64)
    private String author;


    @ManyToOne(fetch = FetchType.EAGER)
    private Album album;

    @Column
    private Boolean downloaded = false;

    @OneToMany(targetEntity = PlayUrlList.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private List<PlayUrlList> playUrlList = new ArrayList<>();

    public static Track build(Tracks.Data.Track track) {
        Track result = new Track();
        result.setTitle(track.getTitle());
        result.setId(Long.valueOf(track.getTrackId()));
        result.setDownloaded(false);
        return result;
    }
}
